import { TableBase, TextTable } from '@/components/public-template';
import { QuestionBase, SelectQuestion, InputQuestion, TimeQuestion } from '@/components/public-template';

class virtualListService {
  getIcons() {
    const icons: TableBase<any>[] = [
      new TextTable({
        key: 'add',
        value: '新增课程111',
        class: 'PlusOutlined',
        actions: {},
        state: {
          methods: 'router',
          url: 'Demo',
          key: ''
        },
        order: 1
      })
    ];

    return icons.sort((a, b) => a.order - b.order);
  }

  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'Filter',
        label: '关键字',
        value: '',
        type: 'selectAll',
        placeholder: '请输入关键字',
        options: [
          {
            label: '关键词1',
            value: 'Filter1'
          },
          {
            label: '关键词2',
            value: 'Filter2'
          },
          {
            label: '关键词3',
            value: 'Filter3'
          },
          {
            label: '关键词4',
            value: 'Filter4'
          }
        ],
        order: 1
      }),

      new SelectQuestion({
        key: 'Type',
        label: '类型',
        value: null,
        options: [
          {
            label: '请选择',
            value: null
          },
          {
            label: '图文课程',
            value: 1
          },
          {
            label: '视频课程',
            value: 2
          }
        ],
        type: 'text',
        order: 4
      }),

      new SelectQuestion({
        key: 'IsActive',
        label: '状态',
        value: null,
        options: [
          {
            label: '请选择',
            value: null
          },
          {
            label: '已上架',
            value: 'true'
          },
          {
            label: '已下架',
            value: 'false'
          }
        ],
        type: 'text',
        order: 4
      })
    ];
    return questions.sort((a, b) => a.order - b.order);
  }

  getTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'name',
        value: '课程名称',
        columns: {
          align: 'right'
        },
        order: 3
      }),

      new TextTable({
        key: 'type',
        value: '课程类型',
        order: 4
      }),

      new TextTable({
        key: 'categoryIds',
        value: '状态',
        type: 'dictionary',
        state: {
          filterName: 'stateType'
        },
        tag: {
          0: 'red',
          1: '#108ee9',
          3: '#87d068'
        },
        order: 4
      }),

      new TextTable({
        key: 'price',
        value: '自定义slot',
        type: 'custom', //本地自定义
        columns: {
          customRender: (data: any) => {
            const result = `自定义${data.value}`;
            return result;
          }
        },
        scopedSlots: { customRender: 'recordName' },
        order: 4
      }),

      new TextTable({
        key: 'marketPrice',
        value: '市场价',
        order: 4
      }),

      new TextTable({
        key: 'buyerCount',
        value: '学员数量',
        order: 4
      }),

      new TextTable({
        key: 'shelvesTime',
        value: '上架时间',
        type: 'time',
        order: 4
      }),

      new TextTable({
        key: 'actions',
        value: '操作',
        order: 9,
        state: {
          width: 200
        },
        handle: [
          {
            type: 'url',
            url: 'Home',
            text: '编辑',
            class: 'text-primary',
            params: [{ id: 'id' }],
            state: {
              key: ''
            }
          },
          {
            type: 'hint',
            url: 'Course/UpdateActive',
            text: '上架',
            class: 'text-primary',
            // showKey: [{ key: 'isActive', value: 1, invert:true   }],
            params: [{ id: 'id' }],
            postType: 'put',
            state: {
              assign: { isActive: true },
              hintData: {
                title: '确定上架该课程吗？'
              },
              key: ''
            }
          },
          {
            type: 'delete',
            url: 'Course/Delete',
            text: '删除',
            class: 'text-error',
            params: [{ id: 'id' }],
            state: {
              key: ''
            }
          }
        ]
      })
    ];

    return tables.sort((a, b) => a.order - b.order);
  }
}

export default new virtualListService();
